#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
#include "serial.h"

com_opt_t com_cfg = {
    .baud_rate = 9600,
        .data_bits = 1,
        .parity = 'N',
        .data_bits = 8
};
int  main()
{
    int fd;
    char in_buf[256]={0};
    char out_buf[256] = {0};
    int rsize;


    fd = open_com("/dev/ttyS1");
    if(fd < 0){
        printf("open com failed\n");
        return -1;
    }

    if(0!=set_com(fd, &com_cfg)){
        printf("set com cfg error\n");
        return -1;
    }
    printf("init succ\n");
    while(1)
    {
        rsize = read(fd,in_buf,8);
        if(rsize ==0){

            printf("time out\n");
            sleep(1);
        }else if(rsize == -1){

            perror("err:");
        }else{
            printf("rsize:%d\n", rsize);
            printf("%c",in_buf[0]);
        }
    }
    return 0;
}